{extend name="../application/admin/view/layout.html" /}

{block name="head"}
<link href="{:staticResource('css/plugins/iCheck/custom.css')}" rel="stylesheet">
{/block}

{block name="content"}

<div class="wrapper wrapper-content animated fadeInRight">
  <div class="col-sm-12">
    <div class="ibox float-e-margins">
      <div class="ibox-content">
        <div class="row">
          <div class="col-sm-9 m-b-xs">

          </div>
          <div class="col-sm-3">
            <div class="input-group">
              <input type="text" placeholder="请输入关键词" class="form-control" id="key" value="{$key}">
              <span class="input-group-btn">
                <button type="button" class="btn btn-primary" onclick="search()"> 搜索</button>
              </span>
            </div>
          </div>
        </div>
        <div class="table-responsive">
          <div class="ibox float-e-margins">
            <div class="ibox-title">
              <button type="button" class="btn btn-primary" onclick="pop_iframe('添加角色',`{:url('admin/role/add')}`)"> 添加角色 </button>
              <button type="button" class="btn btn-danger" id="delete_more"> 批量删除 </button>
              <button type="button" class="btn btn-white" id="refresh-auth" onclick="refresh_auth()" style="float:right;"> 刷新系统权限 </button>
            </div>
            <div class="ibox-content">
              <table class="table table-hover">
                <thead>
                <tr>
                  <th><input type="checkbox" class="i-checks" id="check_all"></th>
                  <th>ID</th>
                  <th>角色名</th>
                  <th>状态</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <form id="check_ids" action="{:url('admin/role/del')}">
                  {foreach $data as $v}
                  <tr>
                    <td>
                      <input type="checkbox" class="i-checks" value="{$v.id}" name="id[]">
                    </td>
                    <td>{$v.id}</td>
                    <td>{$v.name}</td>
                    <td>
                      <div class="switch">
                        <div class="onoffswitch">
                          <input type="checkbox"  class="onoffswitch-checkbox" data-url="{:url('admin/role/status')}" data-id="{$v.id}" id="sw-{$v.id}" {if $v.status == 1}checked{/if}>
                          <label class="onoffswitch-label" for="sw-{$v.id}">
                            <span class="onoffswitch-inner"></span>
                            <span class="onoffswitch-switch"></span>
                          </label>
                        </div>
                      </div>
                    </td>
                    <td>
                      {if $v.id != 1001}
                      <a href="javascript:;" onclick="pop_iframe('编辑角色',`{:url('admin/role/edit',['id' => $v.id])}`)" class="option-btn" title="编辑"><i class="glyphicon glyphicon-pencil text-navy"></i></a>
                      <a href="javascript:;" class="option-btn delete-one" title="删除" data-url="{:url('admin/role/del')}" data-id="{$v.id}"><i class="glyphicon glyphicon-trash text-navy"></i></a>
                      {/if}
                    </td>
                  </tr>
                  {/foreach}
                </form>
                </tbody>
              </table>
            </div>
            {$data|raw}
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



{/block}

{block name="js"}
<!--选择框JS-->
<script src="{:staticResource('js/plugins/iCheck/icheck.min.js')}"></script>


<script>

    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });

    });

    // 搜索
    function search() {
        var key = $('#key').val();
        location.replace("{:url('admin/role/list')}" + '?key=' + key);
    }

    // 刷新系统权限
    function refresh_auth() {
        layer.confirm('刷新操作可能导致权限系统工作异常，请谨慎操作', {icon: 3, title:'提示'}, function(index) {
            http_post("{:url('admin/role/refresh')}", {}, function (res) {
                layer.msg('刷新成功', {icon: 1});
            });
            layer.close(index);
        });
    }
</script>
{/block}

